/**
 * 
 */
package team7.made;

import java.util.ArrayList;
import java.util.List;

/**
 * a session instance for one test
 * - keep track of what questions user answered right or wrong
 * - keep score (future impl)
 * - choose questions from question pool
 * 
 * @author team 7
 *
 */
public class TestSession {

	// how many correct answers ?
	private int numberOfQuestionsCorrect = 0;
	
	// how many incorrect answers ?
	private int numberOfQuestionsIncorrect = 0;
	
	private int numberOfQuestions;
	
	public TestSession(int number){
		numberOfQuestions = number;
	}
	
	/**
	 * start the testing session
	 *  - initialize variables
	 *  - get questions associated with the test type
	 * 
	 * @param testName - name of the test as displayed in the menu
	 * @return array of {@link Question} instances
	 */
	public List<Question> startTest(String testName) {
		numberOfQuestionsCorrect = 0;
		numberOfQuestionsIncorrect = 0;
	    List<Question> questions = new ArrayList<Question>();
	    Question question = null;
	    
	    //Chetan's code - loads entire questions.xml
	    /*while(((question = QuestionsDBase.INSTANCE.nextRandomQuestion()) != null)) {
			 questions.add(question);
		}*/
	    
	    // Jack's code, loads a set number of questions
	    for(int i = 0; i < numberOfQuestions; i++){
	    	question = QuestionsDBase.INSTANCE.nextRandomQuestion();
	    	questions.add(question);
	    }
	    
	    // Return ArrayList
	    return questions;
	    
	    //Commented out for testing purposes
	    //return (Question[]) questions.toArray();
	}	
	
	/**
	 * check if answer choice is correct and increment variables.
	 * 
	 * @param question - Question just answered by user
	 * @param choiceSelected - label of the option selected by user
	 */
	public void setResult(Question question, String choiceSelected) {
		if(!"".equals(choiceSelected) && choiceSelected != null && question != null) {
			if(question.getCorrectOption().equals(choiceSelected)) {
				numberOfQuestionsCorrect++;
			}
			else {
				numberOfQuestionsIncorrect++;
			}
		}
	}

	public int getNumberOfQuestionsCorrect() {
		return numberOfQuestionsCorrect;
	}

	public int getNumberOfQuestionsIncorrect() {
		return numberOfQuestionsIncorrect;
	}

}
